/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package printers;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;

/**
 *
 * @author Renato Rosa <2101076@my.ipleiria.pt>
 */
public class SimplePrintable implements Printable {
    private String message;

    public SimplePrintable(String message) {
        this.message = message;
    }
    
    @Override
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        if (pageIndex > 0) {
            return NO_SUCH_PAGE;
        }
        
        Graphics2D g2d = (Graphics2D) graphics;
        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
        
        // Now we perform our rendering
        
        Font f = new Font("Arial", Font.BOLD, 30);
        g2d.setFont(f);
        g2d.drawString(message, 100, 100);

        // tell the caller that this page is part
        // of the printed document
        return PAGE_EXISTS;
    }
    
}
